package com.qingke.note;


import java.util.regex.Pattern;

import com.qingke.note.command.Command;
import com.qingke.note.command.CommandCode;
import com.qingke.note.command.CommandFactory;
import com.qingke.note.pojo.User;

public class App {

	private static User currentUser ;
	
	private static App instance;
	
	public static App getInstance(){
		if(instance==null){
			instance = new App();
		}
		return instance;
	}

	public User getCurrentUser() {
		return currentUser;
	}

	public void setCurrentUser(User currentUser) {
		App.currentUser = currentUser;
	}



	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Console.println("=====开始=====");
		Console.printHelp();
		while(true){
			Command command = getCmd();
			if(command==null){
				continue;
			}
			command.execute();
		}
	}

	private static Command getCmd() {
		String cmd=null;
		Pattern pattern = Pattern.compile("[0-9a-zA-Z]+");
		while (true) {
			cmd = Console.askInput("cmd");
			if(!pattern.matcher(cmd).find()){
				Console.println("别乱摁，好好输入");
				continue;
			}
			break;
		}
		CommandCode cmdCode = null;
		try {
			cmdCode=CommandCode.valueOf(cmd.toUpperCase());
		} catch (Exception e) {
			Console.println("命令输入有误，请重新输入");
			return null;
		}
		return new CommandFactory().buildCommand(cmdCode);
	}

}
